"""
---------------------------------------------------------------------
- File: schemas.py
- Date: 2025/9/26
- Author: yangzhide
- Email: xxzjyzd@126.com
- Description:
---------------------------------------------------------------------
"""

from pydantic import BaseModel, Field, ConfigDict


# 菜单按钮数据模型
class MenuButton(BaseModel):
    """菜单按钮数据模型"""

    id: str = Field(description="按钮ID")
    button_code: str = Field(description="按钮编码")
    button_desc: str = Field(description="按钮描述")


class MenuMeta(BaseModel):
    """菜单元信息数据模型"""

    # 链接相关
    href: str = Field("", description="外链")
    # 页面行为配置
    multi_tab: bool = Field(False, description="是否支持多页签")
    hide_in_menu: bool = Field(False, description="是否在菜单隐藏")
    redirect: str = Field("", description="重定向路径")

    # 路由配置
    constant: bool = Field(False, description="是否为公共路由")

    # 菜单按钮
    buttons: list[MenuButton] = Field([], description="菜单按钮列表")


class MenuIn(BaseModel):
    """菜单入参数据模型"""

    menu_name: str = Field(description="菜单名称")
    menu_type: str = Field(description="菜单类型")
    route_name: str = Field(description="路由名称")
    icon: str = Field(description="图标名称")
    route_path: str = Field(description="路由路径")
    component: str | None = Field(description="路由组件")
    order: int = Field(description="菜单顺序")
    parent_id: int = Field(description="父菜单ID")
    menu_meta: MenuMeta = Field({}, description="菜单元数据")
    status: str = Field(description="状态")
    redirect: str | None = Field(description="重定向路径")
    constant: bool = Field(description="是否为公共路由")


class MenuOut(MenuIn):
    """菜单数据模型"""

    id: int = Field(description="菜单ID")


class MenuTree(MenuOut):
    """菜单树数据模型"""

    children: list["MenuTree"] = Field([], description="子菜单列表")
    # 开启属性读取模式
    model_config = ConfigDict(from_attributes=True)
